Handle static inline GtkOrdering function
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 4 Mar 2021 22:58:05 +0000 (22:58 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Thu, 11 Mar 2021 16:37:38 +0000 (16:37 +0000)
The introspection scanner does not handle `static inline` functions:
they are not in the shared library, so cannot be dlsym() out of it; and
the `static` keyword tells g-ir-scanner to skip the function declaration
entirely.

We can trick the scanner into thinking the gtk_ordering_from_cmpfunc()
symbol is a real, public one, by declaring and defining a regular
function under the `__GI_SCANNER__` guard; the symbol does not appear
when actually building GTK, or any code using GTK, so we don't risk
collisions.

gtk/gtkenums.h
gtk/gtksorter.c

index 775af29173f13c3782224ed322d5c12ecd103c60..da20f7a87a3b032a63475d61567982a9fcebfca7 100644 (file)
@@ -548,7 +548,7 @@ typedef enum
  * These values can be used with a `GCompareFunc`. However,
  * a `GCompareFunc` is allowed to return any integer values.
  * For converting such a value to a `GtkOrdering` value, use
- * [func@Gtk.ordering_from_cmpfunc].
+ * [func@Gtk.Ordering.from_cmpfunc].
  */
 typedef enum {
   GTK_ORDERING_SMALLER = -1,
@@ -556,6 +556,14 @@ typedef enum {
   GTK_ORDERING_LARGER = 1
 } GtkOrdering;
 
+/* The GI scanner does not handle static inline functions, because
+ * of the `static` keyword; so we clip this out when parsing the
+ * header, and we replace it with a real function in gtksorter.c
+ * that only exists when parsing the source for introspection.
+ */
+#ifdef __GI_SCANNER__
+GtkOrdering     gtk_ordering_from_cmpfunc       (int cmpfunc_result);
+#else
 /**
  * gtk_ordering_from_cmpfunc:
  * @cmpfunc_result: Result of a comparison function
@@ -570,6 +578,7 @@ gtk_ordering_from_cmpfunc (int cmpfunc_result)
 {
   return (GtkOrdering) ((cmpfunc_result > 0) - (cmpfunc_result < 0));
 }
+#endif
 
 /**
  * GtkPageOrientation:
index afd24c13f3ba93764532b409da6dbfc530d19b4c..0ad3c2653b8050a39f1a8823dd57e3a1d2bdebc5 100644 (file)
@@ -364,3 +364,24 @@ gtk_sorter_changed_with_keys (GtkSorter       *self,
 
   gtk_sorter_changed (self, change);
 }
+
+/* See the comment in gtkenums.h as to why we need to play
+ * games with the introspection scanner for static inline
+ * functions
+ */
+#ifdef __GI_SCANNER__
+/**
+ * gtk_ordering_from_cmpfunc:
+ * @cmpfunc_result: Result of a comparison function
+ *
+ * Converts the result of a `GCompareFunc` like strcmp() to a
+ * `GtkOrdering` value.
+ *
+ * Returns: the corresponding `GtkOrdering`
+ **/
+GtkOrdering
+gtk_ordering_from_cmpfunc (int cmpfunc_result)
+{
+  return (GtkOrdering) ((cmpfunc_result > 0) - (cmpfunc_result < 0));
+}
+#endif